home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cowboy / shootout.frm (.txt) < prev    next >
Visual Basic Form  |  1995-09-07  |  14KB  |  388 lines

  1. VERSION 4.00
  2. Begin VB.Form frmShootOut 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Shoot-Out"
  6.    ClientHeight    =   5400
  7.    ClientLeft      =   1620
  8.    ClientTop       =   1755
  9.    ClientWidth     =   6135
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   0
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   5805
  21.    Icon            =   "SHOOTOUT.frx":0000
  22.    KeyPreview      =   -1  'True
  23.    Left            =   1560
  24.    LinkTopic       =   "Form2"
  25.    ScaleHeight     =   5400
  26.    ScaleWidth      =   6135
  27.    Top             =   1410
  28.    Width           =   6255
  29.    Begin VB.Timer tmrMouseCntl 
  30.       Interval        =   22
  31.       Left            =   1380
  32.       Top             =   3780
  33.    End
  34.    Begin VB.CommandButton btnStart 
  35.       Appearance      =   0  'Flat
  36.       BackColor       =   &H80000005&
  37.       Caption         =   "&Start"
  38.       Height          =   375
  39.       Left            =   2580
  40.       TabIndex        =   1
  41.       Top             =   3840
  42.       Width           =   1095
  43.    End
  44.    Begin VB.Timer Timer1 
  45.       Left            =   900
  46.       Top             =   3780
  47.    End
  48.    Begin VB.PictureBox picDesert 
  49.       Appearance      =   0  'Flat
  50.       BackColor       =   &H00C0FFC0&
  51.       ForeColor       =   &H80000008&
  52.       Height          =   3315
  53.       Left            =   180
  54.       ScaleHeight     =   3285
  55.       ScaleWidth      =   5745
  56.       TabIndex        =   0
  57.       Top             =   360
  58.       Width           =   5775
  59.       Begin VB.Image imgRBullet 
  60.          Appearance      =   0  'Flat
  61.          Height          =   480
  62.          Index           =   0
  63.          Left            =   5100
  64.          Picture         =   "SHOOTOUT.frx":030A
  65.          Top             =   1440
  66.          Visible         =   0   'False
  67.          Width           =   480
  68.       End
  69.       Begin VB.Image imgLBullet 
  70.          Appearance      =   0  'Flat
  71.          Height          =   480
  72.          Index           =   0
  73.          Left            =   420
  74.          Picture         =   "SHOOTOUT.frx":0614
  75.          Top             =   1440
  76.          Visible         =   0   'False
  77.          Width           =   480
  78.       End
  79.       Begin VB.Image imgCactus 
  80.          Appearance      =   0  'Flat
  81.          Height          =   480
  82.          Index           =   1
  83.          Left            =   2880
  84.          Picture         =   "SHOOTOUT.frx":091E
  85.          Top             =   2160
  86.          Width           =   480
  87.       End
  88.       Begin VB.Image imgCactus 
  89.          Appearance      =   0  'Flat
  90.          Height          =   480
  91.          Index           =   0
  92.          Left            =   2160
  93.          Picture         =   "SHOOTOUT.frx":0C28
  94.          Top             =   480
  95.          Width           =   480
  96.       End
  97.       Begin VB.Image imgPlayer 
  98.          Appearance      =   0  'Flat
  99.          Height          =   480
  100.          Index           =   1
  101.          Left            =   4920
  102.          Picture         =   "SHOOTOUT.frx":0F32
  103.          Top             =   300
  104.          Width           =   480
  105.       End
  106.       Begin VB.Image imgPlayer 
  107.          Appearance      =   0  'Flat
  108.          Height          =   480
  109.          Index           =   0
  110.          Left            =   360
  111.          Picture         =   "SHOOTOUT.frx":123C
  112.          Top             =   2280
  113.          Width           =   480
  114.       End
  115.    End
  116.    Begin VB.Label Label4 
  117.       Alignment       =   2  'Center
  118.       Appearance      =   0  'Flat
  119.       BackColor       =   &H80000005&
  120.       BackStyle       =   0  'Transparent
  121.       Caption         =   "Player 2 uses the mouse: left button and right button clicks move player, and left mouse double-click fires gun."
  122.       ForeColor       =   &H80000008&
  123.       Height          =   495
  124.       Left            =   180
  125.       TabIndex        =   5
  126.       Top             =   4860
  127.       Width           =   5775
  128.    End
  129.    Begin VB.Label Label3 
  130.       Alignment       =   2  'Center
  131.       Appearance      =   0  'Flat
  132.       BackColor       =   &H80000005&
  133.       BackStyle       =   0  'Transparent
  134.       Caption         =   "Player 1 uses the keyboard: up and down arrow keys move player, and space bar fires gun."
  135.       ForeColor       =   &H80000008&
  136.       Height          =   495
  137.       Left            =   180
  138.       TabIndex        =   4
  139.       Top             =   4380
  140.       Width           =   5835
  141.    End
  142.    Begin VB.Label Label2 
  143.       Alignment       =   1  'Right Justify
  144.       Appearance      =   0  'Flat
  145.       BackColor       =   &H80000005&
  146.       BackStyle       =   0  'Transparent
  147.       Caption         =   "Player 2"
  148.       ForeColor       =   &H80000008&
  149.       Height          =   195
  150.       Left            =   4680
  151.       TabIndex        =   3
  152.       Top             =   120
  153.       Width           =   1215
  154.    End
  155.    Begin VB.Label Label1 
  156.       Appearance      =   0  'Flat
  157.       BackColor       =   &H80000005&
  158.       BackStyle       =   0  'Transparent
  159.       Caption         =   "Player 1"
  160.       ForeColor       =   &H80000008&
  161.       Height          =   195
  162.       Left            =   180
  163.       TabIndex        =   2
  164.       Top             =   120
  165.       Width           =   1215
  166.    End
  167.    Begin VB.Image imgRIP 
  168.       Appearance      =   0  'Flat
  169.       Height          =   480
  170.       Left            =   180
  171.       Picture         =   "SHOOTOUT.frx":1546
  172.       Top             =   3780
  173.       Visible         =   0   'False
  174.       Width           =   480
  175.    End
  176. Attribute VB_Name = "frmShootOut"
  177. Attribute VB_Creatable = False
  178. Attribute VB_Exposed = False
  179. Option Explicit
  180. '----------------------------------------------------------
  181. ' SHOOTOUT.FRM
  182. '----------------------------------------------------------
  183. ' KeyCodes for keyboard action.
  184. Const KEY_SPACE = &H20
  185. Const KEY_UP = &H26
  186. Const KEY_DOWN = &H28
  187. ' Number of Twips to move player on each key or mouse event.
  188. Const PlayerIncrement = 45
  189. ' Constants for mouse action.
  190. Const NO_BUTTON = 0
  191. Const LBUTTON = 1
  192. Const RBUTTON = 2
  193. ' Boolean that indicates if mouse button has been pressed down.
  194. Dim MouseButtonDown As Integer
  195. ' Number of bullets either player can have in use at one time.
  196. Const NUM_BULLETS = 6
  197. ' Booleans indicating if player 0 or player 1 have just fired.
  198. Dim GunFired(0 To 1) As Integer
  199. Private Sub btnStart_Click()
  200. '----------------------------------------------------------
  201. ' Start the game by enabling the main timer and hiding
  202. ' the start button.
  203. '----------------------------------------------------------
  204.     Timer1.Enabled = True
  205.     btnStart.Visible = False
  206. End Sub
  207. Private Function Collided(imgA As Image, imgB As Image) As Integer
  208. '--------------------------------------------------
  209. ' Check if the two Images intersect, using the
  210. ' IntersectRect API call.
  211. '--------------------------------------------------
  212. Dim A As tRect
  213. Dim B As tRect
  214. Dim ResultRect As tRect
  215.     ' Copy information into tRect structure
  216.     A.Left = imgA.Left
  217.     A.Top = imgA.Top
  218.     B.Left = imgB.Left
  219.     B.Top = imgB.Top
  220.     ' Calculate the right and bottoms of rectangles needed by the API call.
  221.     A.Right = A.Left + imgA.Width - 1
  222.     A.Bottom = A.Top + imgA.Height - 1
  223.     B.Right = B.Left + imgB.Width - 1
  224.     B.Bottom = B.Top + imgB.Height - 1
  225.     ' IntersectRect will only return 0 (false) if the
  226.     ' two rectangles do NOT intersect.
  227.     Collided = IntersectRect(ResultRect, A, B)
  228. End Function
  229. Private Sub Form_DblClick()
  230. '----------------------------------------------------------
  231. ' Double-clicking the mouse fires Player 1's gun.
  232. '----------------------------------------------------------
  233. Dim rc As Integer
  234.     If Not Timer1.Enabled Then Exit Sub
  235.     GunFired(1) = True
  236.     rc = sndPlaySound(App.Path & "\BANG.WAV", SND_ASYNC)
  237. End Sub
  238. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  239. '----------------------------------------------------------
  240. ' This event handles Player 0's game action via the
  241. ' keyboard.
  242. '----------------------------------------------------------
  243. Dim rc As Integer
  244. Static InKeyDown As Integer
  245.     If Not Timer1.Enabl